using Aurora.TaskScheduler.Abstractions;
using Aurora.TaskScheduler.Abstractions.BaseModel;
using Aurora.TaskScheduler.DistributedLock.NewLifeRedis;
using Microsoft.Extensions.DependencyInjection;

namespace Aurora.TaskScheduler.DistributedLock;

public class RedisTaskDistributeLockOptionExtension : ITaskScheduleOptionsExtension
{
    private readonly Action<RedisTaskDistributeLockOptions> _configure;

    public RedisTaskDistributeLockOptionExtension(Action<RedisTaskDistributeLockOptions> configure)
    {
        _configure = configure;
    }

    public void AddServices(IServiceCollection services)
    {
        services.AddScoped<ITaskDistributeLock, RedisTaskDistributeLock>();
        services.AddScoped<NewLifeRedisCache>();
        services.Configure(_configure);
        services.AddSingleton<NewLifeRedisFactory>();
    }
}